     AddCSLuaFile( "cl_init.lua" )
     AddCSLuaFile( "shared.lua" )
      
     include('shared.lua')
	 
	 function ENT:SpawnFunction( ply, tr)
		local SpawnPos = tr.HitPos + Vector( 0, 0, 15) 
		local ent = ents.Create( "colonies_headcrabeggfast" )
		ent:SetPos( SpawnPos )
		ent:Spawn()
		return ent
	end

      
    function ENT:Initialize()
		
		self.Entity:SetModel("models/props_junk/PopCan01a.mdl")
		self.Entity:PhysicsInit( SOLID_VPHYSICS ) // Make us work with physics,
		self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) // after all, gmod is a physics
		self.Entity:SetSolid( SOLID_VPHYSICS ) // Toolbox 
		self.Entity:GetPhysicsObject():Wake()
		self.Entity:SetMaterial("models/debug/debugwhite")
		
		self.laid = math.Round(CurTime())
		self.Species = "normal"

		Genetics = {}

		Genetics.Slot1name = ""
		Genetics.Slot1magn = 0

		Genetics.Slot2name = ""
		Genetics.Slot2magn = 0

		Genetics.Slot3name = ""
		Genetics.Slot3magn = 0

		Genetics.Slot4name = ""
		Genetics.Slot4magn = 0

		Genetics.Slot5name = ""
		Genetics.Slot5magn = 0
		
		if not self.FromCrab then self.Entity:FormGenetics() else self.Entity:ExtractGenetics() end

    end
     
     function ENT:OnTakeDamage(dmg)
    
     end

    function table.Random2(tab)  
        local t = table.Copy(tab)  
        return function()  
            if #t == 0 then  
                return  
            end   
           return table.remove(t, math.random(1, #t))  
        end  
    end  

	function ENT:FormGenetics()
	local r = table.Random2(headcrabgenes)

        Genetics.Slot1name = r() 
	Genetics.Slot1magn = math.Rand(0.1,2)

        Genetics.Slot2name = r() 
	Genetics.Slot2magn = math.Rand(0.1,2)

        Genetics.Slot3name = r() 
	Genetics.Slot3magn = math.Rand(0.1,2)

        Genetics.Slot4name = r() 
	Genetics.Slot4magn = math.Rand(0.1,2)

        Genetics.Slot5name = r() 
	Genetics.Slot5magn = math.Rand(0.1,2)
	end

	function ENT:ExtractGenetics()

        Genetics.Slot1name = self.Slot1n
	Genetics.Slot1magn = self.Slot1m


        Genetics.Slot2name = self.Slot2n
	Genetics.Slot2magn = self.Slot2m


        Genetics.Slot3name = self.Slot3n
	Genetics.Slot3magn = self.Slot3m


        Genetics.Slot4name = self.Slot4n
	Genetics.Slot4magn = self.Slot4m


        Genetics.Slot5name = self.Slot5n
	Genetics.Slot5magn = self.Slot5m
	end
	    
	/*---------------------------------------------------------
	Name: OnRemove
	Desc: Called just before entity is deleted
	//-------------------------------------------------------*/
	function ENT:OnRemove()

	end
	  
 	function ENT:Think()
		if math.Round(CurTime()) > self.laid + GetConVarNumber("co_headcrab_eggtime") then
			
		local heady = ents.Create("colonies_headcrab")

		local mutationchance = 2

			if headcrabCount() < GetConVarNumber("co_headcrab_max") then
		local eggtype = math.random(1,100)
		if eggtype <= mutationchance then
		heady = ents.Create("colonies_headcrab")		
		self.Species = "fast"
		elseif eggtype > mutationchance && eggtype < (mutationchance * 2) then 
		heady = ents.Create("colonies_headcrabpoison")
		self.Species = "poison"
		elseif eggtype >= (mutationchance * 2) then 
		heady = ents.Create("colonies_headcrabfast")
		self.Species = "normal"
		end
				undo.ReplaceEntity(self.Entity,heady)
	
				heady:SetPos(self.Entity:GetPos()+Vector(0,0,3))
				
				heady.FromEgg = true	

				heady.Slot1n = Genetics.Slot1name
				heady.Slot1m = Genetics.Slot1magn


				heady.Slot2n = Genetics.Slot2name
				heady.Slot2m = Genetics.Slot2magn


				heady.Slot3n = Genetics.Slot3name
				heady.Slot3m = Genetics.Slot3magn


				heady.Slot4n = Genetics.Slot4name
				heady.Slot4m = Genetics.Slot4magn


				heady.Slot5n = Genetics.Slot5name
				heady.Slot5m = Genetics.Slot5magn
				
				heady:Spawn()
				heady:Activate()
			end
			
			self.Entity:Remove()
		
		end
	end 